﻿//信息基表
//创建时间: 2010-10-19
//创建作者: 李晓忠
//功能说明: CMS系统 信息基表 
//最后修改: 2010-10-19
//最后修改: 2010-10-20 李晓忠 添加保存模型信息。
//最后修改: 2010-10-21 李晓忠 GetDataSet。修改SaveNewDoc,添加DeleteInfoByExtendId
//最后修改: 2010-11-2 李晓忠 添加置顶操作\精华操作\排序操作
//最后修改: 2010-11-17 李晓忠 添加模型信息表某一字段值
//最后修改: 2010-11-22 李晓忠 添加更新计划发布时间
//最后修改: 2010-11-26 李城 添加获取 获取某结点下的已发布信息总和
//最后修改: 2010-11-26 李城 添加获取 获取某结点下的已发布信息总和
using System;
using System.Collections.Generic;
using System.Text;

using System.Data.Common;
using System.Data;
using TRPOP.Common;
using TRPOP.Config;
using TRPOP.CMS.Model;
using TRPOP.CMS.DALFactory;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace TRPOP.CMS.DALSQLServer
{
    public class ContentDAL : IContentDAL
    {
        #region 保存 Save
        public EnumSubmitResult Save(ContentInfo info)
        {
            string strStoreProcedure = SystemInfoHelper.getSystemInfo().DBprefixTableName + "_" + "Content_Save";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetStoredProcCommand(strStoreProcedure);

            odbDataBase.AddInParameter(odbCommand, "@Status", System.Data.DbType.Int32, info.Status);
            odbDataBase.AddInParameter(odbCommand, "@SelfPSN", System.Data.DbType.String, info.SelfPSN);
            odbDataBase.AddInParameter(odbCommand, "@SelfURL", System.Data.DbType.String, info.SelfURL);
            odbDataBase.AddInParameter(odbCommand, "@PubStatus", System.Data.DbType.Int32, info.PubStatus);
            odbDataBase.AddInParameter(odbCommand, "@NodeId", System.Data.DbType.Int32, info.NodeId);
            odbDataBase.AddInParameter(odbCommand, "@NodeContentSortId", System.Data.DbType.Int32, info.NodeContentSortId);
            odbDataBase.AddInParameter(odbCommand, "@ExtendId", System.Data.DbType.Int32, info.ExtendId);
            odbDataBase.AddInParameter(odbCommand, "@Name", System.Data.DbType.String, info.Name);
            odbDataBase.AddInParameter(odbCommand, "@ExtendTableName", System.Data.DbType.String, info.ExtendTableName);
            odbDataBase.AddInParameter(odbCommand, "@Template", System.Data.DbType.String, info.Template);
            odbDataBase.AddInParameter(odbCommand, "@HtmlName", System.Data.DbType.String, info.HtmlName);
            odbDataBase.AddInParameter(odbCommand, "@Url", System.Data.DbType.String, info.Url);
            odbDataBase.AddInParameter(odbCommand, "@ExtraUrl", System.Data.DbType.String, info.ExtraUrl);
            odbDataBase.AddInParameter(odbCommand, "@TopWeight", System.Data.DbType.Int32, info.TopWeight);
            odbDataBase.AddInParameter(odbCommand, "@DisplayOrder", System.Data.DbType.Int32, info.DisplayOrder);
            odbDataBase.AddInParameter(odbCommand, "@Type", System.Data.DbType.Int32, info.Type);
            odbDataBase.AddInParameter(odbCommand, "@EliteWeight", System.Data.DbType.Int32, info.EliteWeight);
            odbDataBase.AddInParameter(odbCommand, "@PubUserId", System.Data.DbType.Int32, info.PubUserId);
            odbDataBase.AddInParameter(odbCommand, "@PubTime", System.Data.DbType.DateTime, info.PubTime);
            odbDataBase.AddInParameter(odbCommand, "@AddUserId", System.Data.DbType.Int32, info.AddUserId);
            odbDataBase.AddInParameter(odbCommand, "@AddTime", System.Data.DbType.DateTime, info.AddTime);
            odbDataBase.AddInParameter(odbCommand, "@UpdateUserId", System.Data.DbType.Int32, info.UpdateUserId);
            odbDataBase.AddInParameter(odbCommand, "@UpdateTime", System.Data.DbType.DateTime, info.UpdateTime);
            odbDataBase.AddInParameter(odbCommand, "@Click", System.Data.DbType.Int32, info.Click);
            odbDataBase.AddInParameter(odbCommand, "@SEOTitle", System.Data.DbType.String, info.SEOTitle);
            odbDataBase.AddInParameter(odbCommand, "@SEOKey", System.Data.DbType.String, info.SEOKey);
            odbDataBase.AddInParameter(odbCommand, "@SEODescription", System.Data.DbType.String, info.SEODescription);
            odbDataBase.AddInParameter(odbCommand, "@ReadLimit", System.Data.DbType.Int32, info.ReadLimit);
            odbDataBase.AddInParameter(odbCommand, "@Extcredits1", System.Data.DbType.Decimal, info.Extcredits1);
            odbDataBase.AddInParameter(odbCommand, "@Extcredits2", System.Data.DbType.Decimal, info.Extcredits2);
            odbDataBase.AddInParameter(odbCommand, "@Extcredits3", System.Data.DbType.String, info.Extcredits3);
            odbDataBase.AddInParameter(odbCommand, "@Extcredits4", System.Data.DbType.String, info.Extcredits4);
            odbDataBase.AddInParameter(odbCommand, "@Extcredits5", System.Data.DbType.String, info.Extcredits5);
            odbDataBase.AddParameter(odbCommand, "@ContentId", System.Data.DbType.Int32, ParameterDirection.InputOutput, null, DataRowVersion.Default, info.ContentId);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                info.ContentId = (int)odbDataBase.GetParameterValue(odbCommand, "@ContentId");
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }

        #endregion

        #region 获取实体 GetInfoById
        public ContentInfo GetInfoById(int id)
        {
            string strSqlString = "SELECT * FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE ContentId=" + id;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);
            ContentInfo oInfo = null;
            try
            {
                using (IDataReader reader = odbDataBase.ExecuteReader(odbCommand))
                {
                    if (reader.Read())
                    {
                        oInfo = new ContentInfo();
                        ModelHelper.LoadInfoData(oInfo, reader);
                    }
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return oInfo;
        }
        #endregion

        #region 逻辑删除 DeleteInfoById
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return DeleteInfoByIds(id.ToString());
        }
        #endregion

        #region 逻辑删除 DeleteInfoByIds
        /// <summary>
        /// 逻辑删除 PubStatus=-1
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            string strSqlString = "UPDATE   " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET PubStatus=-1 WHERE ContentId in(" + ids + ")";          
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 恢复逻辑删除 RestoreDeleteInfoByIds
        /// <summary>
        /// 恢复逻辑删除 PubStatus=0
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public EnumSubmitResult RestoreDeleteInfoByIds(string ids)
        {
            string strSqlString = "UPDATE   " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET PubStatus=0 WHERE ContentId in(" + ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region  永久删除 DestroyDeleteInfoByIds
        /// <summary>
        /// 永久删除, 后面需要添加删除相关评论等信息。
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public EnumSubmitResult DestroyDeleteInfoByIds(string ids)
        {
            string strSqlString = "DELETE FROM    " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE ContentId in(" + ids + ")";
            string strSqlStrDelete = " DECLARE @teble NVARCHAR(100);"
            + " SELECT TOP 1 @teble= ExtendTableName  FROM " + SystemInfoHelper.getSystemInfo().DBOwner + ".cms_content_Content WHERE ContentId IN(" + ids + ") AND [Type]=1;"
            + " EXECUTE('DELETE  FROM '+  @teble+' where  '+@teble+'id in (SELECT   ExtendId FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE ContentId IN(" + ids + ") AND [Type]=1)');";
            strSqlString = strSqlStrDelete + strSqlString;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region  永久删除 DestroyDeleteInfoByNodeId
        /// <summary>
        /// 永久删除, 后面需要添加删除相关评论等信息。
        /// </summary>
        /// <param name="nodeid">结点Id</param>
        /// <returns></returns>
        public EnumSubmitResult DestroyDeleteInfoByNodeId(int nodeid)
        {
            string strSqlString = "DELETE FROM    " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE Nodeid ="+nodeid+" ";
            string strSqlStrDelete = " DECLARE @teble NVARCHAR(100);"
            + " SELECT TOP 1 @teble= ExtendTableName  FROM " + SystemInfoHelper.getSystemInfo().DBOwner + ".cms_content_Content WHERE Nodeid =" + nodeid + "  AND [Type]=1; "
           + " if(@teble <> null) BEGIN "
            + " EXECUTE('DELETE  FROM '+  @teble+' where  '+@teble+'id in (SELECT   ExtendId FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE Nodeid =" + nodeid + "  AND [Type]=1)');"
            + " DELETE FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE [Type] IN (0,2) AND ExtendId IN(SELECT ExtendId FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE NodeId=" + nodeid + " AND [Type]=1); "
            + " END ";

            strSqlString = strSqlStrDelete + strSqlString;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(strSqlString, oeException);
            }
            return enmResult;
        }
        #endregion

        #region  清空回收站 EmptyRecycleByNodeId
        public EnumSubmitResult EmptyRecycleByNodeId(int NodeId)
        {
            string strSqlString = "DELETE FROM    " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE  PubStatus=-1 and NodeId="+NodeId+";";
            string strSqlStrDelete = " DECLARE @teble NVARCHAR(100);"
            + "SELECT TOP 1 @teble= ExtendTableName  FROM " + SystemInfoHelper.getSystemInfo().DBOwner + ".cms_content_Content WHERE  PubStatus=-1 and NodeId=" + NodeId + "  AND [Type]=1;"
            + " if(@teble <> null) BEGIN "
            + " EXECUTE('DELETE  FROM '+  @teble+' where  '+@teble+'id in (SELECT   ExtendId FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE  PubStatus=-1 and NodeId=" + NodeId + "  AND [Type] in (1,3))');"
            + " END";

            strSqlString = strSqlStrDelete + strSqlString;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 自定义列表（无分页） GetListByCondition
        public List<ContentInfo> GetListByCondition(int topn, string condition, string orderby)
        {
            string strSqlString = "SELECT ";
            if (topn > 0)
            {
                strSqlString += " TOP " + topn;
            }
            strSqlString += " * FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE 1=1 "; if (condition != "")
            {
                strSqlString += condition;
            }
            if (orderby != "")
            {
                strSqlString += " ORDER BY " + orderby;
            }
            else
            {
                strSqlString += " ORDER BY ContentId DESC ";
            }

            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);
            List<ContentInfo> olstInfo = new List<ContentInfo>(); ContentInfo oInfo = null;
            try
            {
                using (IDataReader reader = odbDataBase.ExecuteReader(odbCommand))
                {
                    while (reader.Read())
                    {
                        oInfo = new ContentInfo();
                        ModelHelper.LoadInfoData(oInfo, reader);
                        olstInfo.Add(oInfo);
                    }
                }
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return olstInfo;
        }
        #endregion

        #region 自定义列表（分页） GetListByPager
        /// <summary>
        /// 获取信息 GetDataSet
        /// </summary>
        /// <param name="strTable">表名</param>
        /// <param name="strFields">字段</param>
        /// <param name="strCondition">条件</param>
        /// <param name="strOrderBy">排序</param>
        /// <returns></returns>
        public List<ContentInfo> GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            string strStoreProcedure = SystemInfoHelper.getSystemInfo().PagerStoreProcedureName;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetStoredProcCommand(strStoreProcedure);
            List<ContentInfo> olstInfo = new List<ContentInfo>(); ContentInfo oInfo = null;
            odbDataBase.AddInParameter(odbCommand, "@TableName", System.Data.DbType.String, SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content");
            odbDataBase.AddInParameter(odbCommand, "@ShowColumns", System.Data.DbType.String, "*");
            odbDataBase.AddInParameter(odbCommand, "@pageNumber", System.Data.DbType.Int32, pageNumber);
            odbDataBase.AddInParameter(odbCommand, "@pageSize", System.Data.DbType.Int32, pageSize);
            odbDataBase.AddInParameter(odbCommand, "@condition", System.Data.DbType.String, condition);
            odbDataBase.AddInParameter(odbCommand, "@orderby", System.Data.DbType.String, orderby);
            odbDataBase.AddOutParameter(odbCommand, "@recordCount", System.Data.DbType.Int32, 0);
            try
            {
                using (IDataReader reader = odbDataBase.ExecuteReader(odbCommand))
                {
                    while (reader.Read())
                    {
                        oInfo = new ContentInfo();
                        ModelHelper.LoadInfoData(oInfo, reader);
                        olstInfo.Add(oInfo);
                    }
                }
                recordCount = int.Parse(odbCommand.Parameters["@RecordCount"].Value.ToString());
            }
            catch (Exception oeException)
            {
               throw new Exception(oeException.Message, oeException);
            }
            return olstInfo;
        }
        #endregion

        #region 分页获取ContentId
        /// <summary>
        /// 获取ContentId
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public List<ContentInfo> GetContetnIDListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            string strStoreProcedure = SystemInfoHelper.getSystemInfo().PagerStoreProcedureName;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetStoredProcCommand(strStoreProcedure);
            List<ContentInfo> olstInfo = new List<ContentInfo>(); ContentInfo oInfo = null;
            odbDataBase.AddInParameter(odbCommand, "@TableName", System.Data.DbType.String, SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content");
            odbDataBase.AddInParameter(odbCommand, "@ShowColumns", System.Data.DbType.String, "ContentId");
            odbDataBase.AddInParameter(odbCommand, "@pageNumber", System.Data.DbType.Int32, pageNumber);
            odbDataBase.AddInParameter(odbCommand, "@pageSize", System.Data.DbType.Int32, pageSize);
            odbDataBase.AddInParameter(odbCommand, "@condition", System.Data.DbType.String, condition);
            odbDataBase.AddInParameter(odbCommand, "@orderby", System.Data.DbType.String, orderby);
            odbDataBase.AddOutParameter(odbCommand, "@recordCount", System.Data.DbType.Int32, 0);
            try
            {
                using (IDataReader reader = odbDataBase.ExecuteReader(odbCommand))
                {
                    while (reader.Read())
                    {
                        oInfo = new ContentInfo();
                        ModelHelper.LoadInfoData(oInfo, reader);
                        olstInfo.Add(oInfo);
                    }
                }
                recordCount = int.Parse(odbCommand.Parameters["@RecordCount"].Value.ToString());
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return olstInfo;
        }
        #endregion

        #region 保存信息 SaveNewDoc
        /// <summary>
        /// 保存信息
        /// </summary>
        /// <param name="info">基本信息</param>
        /// <param name="model">模型</param>
        /// <param name="modelfieldlist">模型字段</param>
        /// <returns></returns>
        public EnumSubmitResult SaveNewDoc(ContentInfo info, List<ModelFieldInfoWithTableName> modelfieldlist)
        {
            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = null;
            string strTableName="";
            if (info.ContentId > 0)
            {
                #region 更新
                string strUpdateSQL = "";
                string strSetVal = "";
                
                    #region 拼接Update SQL语句
                    
                    int i = 0;
                    foreach (ModelFieldInfoWithTableName fieldInfo in modelfieldlist)
                    {
                        if (i == 0)
                        {
                            strTableName=fieldInfo.TableName;
                            #region
                           
                           
                            if (fieldInfo.FieldTypeStr == "int")
                            {                               
                                strSetVal = string.Format(" [{0}]={1}", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            else if (fieldInfo.FieldTypeStr == "bit")
                            {
                                strSetVal = string.Format(" [{0}]={1}", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            else
                            {
                                strSetVal = string.Format(" [{0}]='{1}'", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            #endregion
                        }
                        else
                        {
                            #region
                            if (fieldInfo.FieldTypeStr == "int")
                            {
                                strSetVal += string.Format(" ,[{0}]={1}", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            else if (fieldInfo.FieldTypeStr == "bit")
                            {
                                strSetVal += string.Format(" ,[{0}]={1}", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            else
                            {
                                strSetVal += string.Format(" ,[{0}]='{1}'", fieldInfo.FieldName, fieldInfo.DefaultValue);
                            }
                            #endregion
                        }
                        i++;
                    }
                    strUpdateSQL = string.Format(" UPDATE [{0}]  SET {1} WHERE {0}id={2} ", strTableName, strSetVal, info.ExtendId);
                    #endregion

                if (strTableName!="")
                {
                    #region 操作数据库
                    try
                    {
                        odbCommand = odbDataBase.GetSqlStringCommand(strUpdateSQL);
                        int intExtendId = odbDataBase.ExecuteNonQuery(odbCommand);                       
                        if (intExtendId > 0)
                        {                         
                            enmResult = Save(info);//保存基本信息
                            return enmResult;
                        }
                        else
                        {
                            //保存失败
                            enmResult = EnumSubmitResult.Failed;
                            return enmResult;
                        }
                    }
                    catch (Exception oeException)
                    {
                        throw new Exception(oeException.Message, oeException);
                    }
                    #endregion
                }
                else
                {
                    throw new Exception("没有传递表名信息");
                }
                #endregion
            }
            else
            {
                #region 新增

                string strInsertSQL = "";
                string strInsertFields = "";
                string strInsertVal = "";
                
                    #region 拼接Insert SQL语句
                    int i = 0;
                    foreach (ModelFieldInfoWithTableName fieldInfo in modelfieldlist)
                    {
                        if (i == 0)
                        {
                            #region
                            strTableName = fieldInfo.TableName;
                            strInsertFields = string.Format(" [{0}]", fieldInfo.FieldName);
                            if (fieldInfo.FieldTypeStr == "int")
                            {
                                strInsertVal = string.Format(" {0}", fieldInfo.DefaultValue);
                            }
                            else if (fieldInfo.FieldTypeStr == "bit")
                            {
                                strInsertVal = string.Format(" {0}", fieldInfo.DefaultValue);
                            }
                            else
                            {
                                strInsertVal = string.Format(" '{0}'", fieldInfo.DefaultValue);
                            }
                            #endregion
                        }
                        else
                        {
                            #region
                            strInsertFields += string.Format(" ,[{0}]", fieldInfo.FieldName);
                            if (fieldInfo.FieldTypeStr == "int")
                            {
                                strInsertVal += string.Format(", {0}", fieldInfo.DefaultValue);
                            }
                            else if (fieldInfo.FieldTypeStr == "bit")
                            {
                                strInsertVal += string.Format(" ,{0}", fieldInfo.DefaultValue);
                            }
                            else
                            {
                                strInsertVal += string.Format(" ,'{0}'", fieldInfo.DefaultValue);
                            }
                            #endregion
                        }
                        i++;
                    }
                    strInsertSQL = string.Format(" INSERT into [{0}] ({1}) VALUES ({2}) ; IF(@@Error=0)SELECT SCOPE_IDENTITY() ELSE SELECT 0 ", strTableName, strInsertFields, strInsertVal);
                    #endregion
                    if (strTableName != "")
                    {

                        #region 操作数据库
                        try
                        {
                            odbCommand = odbDataBase.GetSqlStringCommand(strInsertSQL);
                            int intExtendId = Convert.ToInt32(odbDataBase.ExecuteScalar(odbCommand));//执行保存并还回Id
                            if (intExtendId > 0)
                            {
                                info.ExtendId = intExtendId;
                                enmResult = Save(info);//保存基本信息
                                return enmResult;
                            }
                            else
                            {
                                //保存失败
                                enmResult = EnumSubmitResult.Failed;
                                return enmResult;
                            }
                        }
                        catch (Exception oeException)
                        {
                            throw new Exception(oeException.Message, oeException);
                        }
                        #endregion
                    }
                    else
                    {
                        throw new Exception("没有传递表名信息");
                    }
                #endregion
            }

            
        }
        #endregion

        #region 获取信息 GetDataSet
        public DataSet GetDataSet(string strTable, string strFields, string strCondition, string strOrderBy)
        {
            DataSet ds = new DataSet();           
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = null;
            string strSelectSQL ="";
            if (strFields == "") { strFields = "*"; }
            if (strTable != "")
            {
                strSelectSQL = string.Format("SELECT {1} FROM {0} ", strTable, strFields);
                if (strCondition != "")
                {
                    strSelectSQL +=  "  WHERE 1=1 " + strCondition;
                }

                if (strOrderBy != "")
                {
                    strSelectSQL += strOrderBy.ToLower().IndexOf("order by") >= 0 ? strOrderBy : " ORDER BY" + strOrderBy;
                }

                odbCommand = odbDataBase.GetSqlStringCommand(strSelectSQL);
                try 
                {                    
                    using (ds = odbDataBase.ExecuteDataSet(odbCommand))
                    {
                       
                    }
                }
                catch (Exception oeException)
                {
                    throw new Exception(oeException.Message, oeException);
                }
            }
            return ds;
        }
        #endregion

        #region 删除信息  DeleteInfoByExtendId
        public EnumSubmitResult DeleteInfoByExtendId(int ExtendId, string ExtendTableName)
        {
            string strSqlString = "DELETE FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE ExtendId ="+ExtendId+"; DELETE FROM "+ExtendTableName +" WHERE "+ExtendTableName+"id="+ExtendId;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 置顶操作 SetTopWeightByIds
        public EnumSubmitResult SetTopWeightByIds( string Ids, int TopWeight)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET TopWeight=" + TopWeight + "  WHERE   ContentId in(" + Ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 精华操作 SetEliteWeightByIds
        public EnumSubmitResult SetEliteWeightByIds(string Ids, int EliteWeight)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET EliteWeight=" + EliteWeight + "  WHERE  ContentId  in(" + Ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 排序操作 SetDisplayOrderByIds
        public EnumSubmitResult SetDisplayOrderByIds( string Ids, int DisplayOrder)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET DisplayOrder=" + DisplayOrder + "  WHERE   ContentId  in(" + Ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 更新点击数 SetClickByInfoIds
        public EnumSubmitResult SetClickByInfoId(string ids, int Click)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET Click=" + Click + "  WHERE ContentId  in(" + ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 点击数加1 SetClickAdd
        public EnumSubmitResult SetClickAdd(string ids)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET Click=Click+1   WHERE ContentId  in(" + ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 文章转移操作 CutDocToNewNode
        public EnumSubmitResult CutDocToNewNode(string Ids, int NodeId)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET PubStatus=0 ,  NodeId=" + NodeId + "  WHERE   ContentId  in(" + Ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 文章复制操作CopyDocToNewNode
        public EnumSubmitResult CopyDocToNewNode(string ids,int NodeId,int AdminId,DateTime AdminTime)
        {
            #region 复制语句
            string strSqlString = "INSERT INTO  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content"
          +" ([Status]"
           +",[PubStatus]"
          +" ,[NodeId]"
          +" ,[NodeContentSortId]"
          +" ,[ExtendId]"
          +" ,[ExtendTableName]"
          +" ,[Name]"
          +" ,[Template]"
          +" ,[HtmlName]"
          +" ,[Url]"
          +" ,[ExtraUrl]"
          +" ,[TopWeight]"
           +",[DisplayOrder]"
           +",[Type]"
           +",[EliteWeight]"
           +",[PubUserId]"
           +",[PubTime]"
           +",[AddUserId]"
           +",[AddTime]"
           +",[UpdateUserId]"
           +",[UpdateTime]"
           +",[Click]"
           +",[SEOTitle]"
           +",[SEOKey]"
           +",[SEODescription]"
           +",[ReadLimit]"
           +",[Extcredits1]"
           +",[Extcredits2]"
           +",[Extcredits3]"
           +",[Extcredits4]"
           +",[Extcredits5])"
     +"SELECT "
        +"   [Status]"
           +",0"
           + "," + NodeId + ""
          +" ,0"
           +",ExtendId"
           +",ExtendTableName"
           +",Name"
           +",''"
           +",''"
           +",''"
          +" ,''"
           +",0"
           +",0"
           +",1"
           +",0"
           + "," + AdminId + ""
           +",'"+AdminTime+"'"
           + "," + AdminId + ""
           +",'"+AdminTime+"'"
           + "," + AdminId + ""
           +",'"+AdminTime+"'"
           +",0"
           +",''"
           +",''"
           +",''"
           +",0"
           +",0"
           +",0"
           +",''"
           +",''"
           +",''"
           + "FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content  WHERE ContentId IN(" + ids + ")";
            #endregion
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(strSqlString, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 获取信息表1条数据
        public List<ModelFieldInfoWithTableName> GetContentData(string tableName, int ExtendId, List<ModelFieldInfoWithTableName> m_ModelFieldInfoList)
        {
            DataSet ds = GetDataSet(tableName, "", " and " + tableName + "id=" + ExtendId, "");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                foreach (ModelFieldInfoWithTableName FieldInfo in m_ModelFieldInfoList)
                {
                    //需要查询模型表赋值
                    if (ds.Tables[0].Columns.Contains(FieldInfo.FieldName))
                    {
                        if (FieldInfo.FieldTypeStr == "bit")
                        {
                            FieldInfo.DefaultValue = Convert.ToBoolean(dr[FieldInfo.FieldName]) ? "1" : "0";
                        }
                        else
                        {
                            FieldInfo.DefaultValue = dr[FieldInfo.FieldName].ToString();
                        }
                    }

                }
            }
            else
            {
                m_ModelFieldInfoList = new List<ModelFieldInfoWithTableName>();
            }

            return m_ModelFieldInfoList;
        }
        #endregion

        #region 添加模型信息表某一字段值
        /// <summary>
        /// 添加模型信息表某一字段值
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="strField">字段</param>
        /// <param name="ContentId">基表信息Id</param>
        /// <returns></returns>
        public object GetFieldValue(string tableName, string strField, int ContentId)
        {
            object obj = null;
            DataSet ds = GetDataSet(tableName, strField, " and " + tableName + "id= ( SELECT ExtendId FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content   WHERE ContentId=" + ContentId+")", "");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];                
                return dr[0];
            }
            

            return obj;
        }
        #endregion

        #region 更新计划发布时间
        /// <summary>
        /// 更新计划发布时间
        /// </summary>
        /// <param name="Ids"></param>
        /// <param name="PubTime"></param>
        /// <returns></returns>
        public EnumSubmitResult SetPubTimeByIds(string Ids, DateTime PubTime)
        {
            string strSqlString = "UPDATE  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content SET PubTime='" + PubTime + "'  WHERE  ContentId  in(" + Ids + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region  获取某结点下的信息总和
        /// <summary>
        /// 获取某结点下的信息总和
        /// </summary>
        /// <param name="strNodeId"></param>
        /// <param name="strPubstatus"></param>
        /// <returns></returns>
        public int GetContentCount(string strNodeId, string strPubstatus)
        {
            string strSqlString = "SELECT COUNT(0) FROM  " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content ";
            strSqlString += " where NodeId in (" + strNodeId + ") ";
            strSqlString += " and PubStatus in (  " + strPubstatus.ToString() + ")";
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);
            DataTable oDataTable = new DataTable();
            try
            {
                return int.Parse(odbDataBase.ExecuteDataSet(odbCommand).Tables[0].Rows[0][0].ToString());
            }
            catch (Exception oeException)
            {
                return 0;
                throw new Exception(oeException.Message, oeException);
            }
        }
        #endregion

        #region 获取关键字相关信息的Id
        public string GetExtendIdBySearchKey(string SearchKey, int NodeId)
        {
            StringBuilder strBuilder = new StringBuilder("0");
            ModelFieldDAL modelfield = new ModelFieldDAL();
            string tableName = "";
            string baseTableName = SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content ";
            string strCondition = "";
            string strField = "ExtendId";
            foreach(ModelFieldInfoWithTableName FieldInfo in  modelfield.GetWithTableNameListByNodeId(NodeId))
            {
                if (tableName == "")
                {
                    tableName = FieldInfo.TableName;                  
                }
                if (FieldInfo.IsSearch)
                {
                    if (FieldInfo.FieldTypeStr == "varchar" || FieldInfo.FieldTypeStr == "nvarchar")
                    {
                        if (strCondition == "")
                        {
                            strCondition += "  " + tableName + "." + FieldInfo.FieldName + " like '%" + SearchKey + "%' ";
                        }
                        else
                        {
                            strCondition += " OR " + tableName + "." + FieldInfo.FieldName + " like '%" + SearchKey + "%' ";
                        }
                    }
                }
            }
            if (strCondition != "")
            {
                strCondition = " and (" + strCondition + ")";
                strCondition = " and  " + baseTableName + ".NodeId = " + NodeId + " and  " + baseTableName + ".ExtendId = " + tableName + "." + tableName + "id" + "  " + strCondition;
                tableName = tableName + " ," + baseTableName;
                strField =" top 1000 "+  baseTableName + "." + strField;
                DataSet ds = GetDataSet(tableName, strField, strCondition, "");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (dr[0] != null && dr[0].ToString().IsEmpty() == false)
                            strBuilder.Append("," + dr[0].ToString());
                    }
                }
            }
            return strBuilder.ToString();
        }
        /// <summary>
        /// 拼接查询的SQL语句
        /// </summary>
        /// <param name="SearchKey"></param>
        /// <param name="NodeId"></param>
        /// <returns></returns>
        public string GetExtendIdBySearchKeySQL(string SearchKey, int NodeId)
        {
            string tableName = string.Empty;
            string baseTableName = SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content ";
            StringBuilder strCondition = new StringBuilder();
            string strField = string.Empty;
            foreach (ModelFieldInfoWithTableName FieldInfo in new ModelFieldDAL().GetWithTableNameListByNodeId(NodeId))
            {
                if (tableName == string.Empty)
                {
                    tableName = FieldInfo.TableName;
                }
                if (FieldInfo.IsSearch && (FieldInfo.FieldTypeStr == "varchar" || FieldInfo.FieldTypeStr == "nvarchar"))
                {
                    strCondition.Append(" OR " + tableName + "." + FieldInfo.FieldName + " like '%" + SearchKey + "%' ");
                }
            }
            if (strCondition.ToString().IsEmpty()==false)
            {
                strCondition.Insert(0, " and (   1=2  ");
                strCondition.Append("                 ) ");
                strCondition.Insert(0, "   and  " + baseTableName + ".ExtendId = " + tableName + "." + tableName + "id" + "  ");
                strCondition.Insert(0, "   and  " + baseTableName + ".NodeId = " + NodeId);
                tableName = tableName + " ," + baseTableName;
                strField = "  " + baseTableName + ".ExtendId";
                return string.Format("SELECT {0} FROM {1} WHERE 1=1 {2} ", strField, tableName, strCondition.ToString());
            }
            return string.Empty;
        }
        #endregion

        #region 获取实链接的虚链接信息
        /// <summary>
        /// 获取实链接的虚链接信息
        /// </summary>
        /// <param name="ContentIds"></param>
        /// <returns></returns>
        public List<ContentInfo> GetVirtualLink(string ContentIds)
        {
            List<ContentInfo> m_ContentInfoList = new List<ContentInfo>();
            string strCondition = " AND ExtendId IN (   SELECT ExtendId FROM   " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE ContentId IN ( " + ContentIds + "))  AND ContentId NOT IN ( " + ContentIds + ")  AND [Type]=" + (int)LinkType.EnumElement.VirtualLink;
            m_ContentInfoList = GetListByCondition(0, strCondition, "");
            return m_ContentInfoList;
        }
        #endregion

        #region 删除基表信息  DeleteContendInfoByContendId
        /// <summary>
        /// 删除基表信息(只删除基表信息)
        /// </summary>
        /// <param name="ContendId"></param>
        /// <returns></returns>
        public EnumSubmitResult DeleteContendInfoByContendId(int ContendId)
        {
            string strSqlString = "DELETE FROM " + SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content WHERE ContentId =" + ContendId;
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSqlString);

            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region  同步虚结点
        /// <summary>
        /// 同步虚结点
        /// </summary>
        /// <param name="oVirualNode"></param>
        /// <param name="oParentNode"></param>
        /// <param name="intUserID"></param>
        /// <returns></returns>
        public EnumSubmitResult UpdateAllSyncContent(NodeInfo oVirualNode,NodeInfo oParentNode,int intUserID)
        {

            string strSQLExecute = string.Format
                                   (@"
                                    insert into {0}_content_Content
                                    select
                                               [Status]
                                               ,{1} as [PubStatus]
                                               ,{2} as [NodeId]
                                               ,[NodeContentSortId]
                                               ,[ExtendId]
                                               ,[ExtendTableName]
                                               ,[Name]
                                               ,'' as [Template] 
                                               ,'' as [SelfPSN]  
                                               ,'' as [SelfURL] 
                                               ,[HtmlName]
                                               ,'' as [Url]
                                               ,[ExtraUrl]
                                               ,[TopWeight]
                                               ,[EliteWeight]
                                               ,[DisplayOrder]
                                               ,[PubUserId]
                                               ,{3} as [Type]
                                               ,getdate() as [PubTime] 
                                               ,{4} as [AddUserId]
                                               ,getdate() as [AddTime]
                                               ,{4} as [UpdateUserId] 
                                               ,getdate() as [UpdateTime]
                                               ,[Click]
                                               ,[SEOTitle]
                                               ,[SEOKey]
                                               ,[SEODescription]
                                               ,[ReadLimit]
                                               ,[Extcredits1]
                                               ,[Extcredits2]
                                               ,[Extcredits3]
                                               ,[Extcredits4]
                                               ,[Extcredits5]
                                    from {0}_content_content ParentTable
                                    where ParentTable.nodeid={5} and ParentTable.PubStatus=1 and ParentTable.[Type]=1 and
                                          ParentTable.[ExtendId] >  isnull(( select   max([ExtendId]) from  {0}_content_content where nodeid={2} ),0)
                                    order by ExtendId asc
                                    "
                                    //and ParentTable.[ExtendId] not in 
                                    // ( select [ExtendId] from  {0}_content_content where nodeid={2} )
                                    //"
                                    , SystemInfoHelper.getSystemInfo().DBprefixTableName//数据表前缀
                                    , (int)TRPOP.Common.PubStatus.EnumElement.UnPublish
                                    , oVirualNode.NodeId
                                    ,(int) LinkType.EnumElement.VirtualLink
                                    , intUserID
                                    , oParentNode.NodeId
                                   );
            SqlDatabase odbDataBase = new SqlDatabase(SystemInfoHelper.getSystemInfo().CMSDataBaseConnection);
            DbCommand odbCommand = odbDataBase.GetSqlStringCommand(strSQLExecute);
            EnumSubmitResult enmResult = EnumSubmitResult.Failed;
            try
            {
                odbDataBase.ExecuteNonQuery(odbCommand);
                enmResult = EnumSubmitResult.Success;
                if (odbCommand != null && odbCommand.Connection != null)
                    odbCommand.Connection.Close();
            }
            catch (Exception oeException)
            {
                throw new Exception(oeException.Message, oeException);
            }
            return enmResult;
        }
        #endregion

        #region 获取信息列表
        /// <summary>
        /// 获取信息列表（$_title:标题字段）
        /// </summary>
        /// <param name="nodeId"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataSet GetContentListByPager(int nodeId, int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            recordCount = 0;
            string strTableName = "";
            string strBaseTable = SystemInfoHelper.getSystemInfo().DBprefixTableName + "_content_Content";
            string strExtTable = "";
            string strShowColumns = "";
            string strBaseColumns = strBaseTable + ".*";
            string strExtColumns = "";
            condition = "  " + condition;

            #region 模型表列表字段
            List<ModelFieldInfoWithTableName> TitleList = (new ModelFieldDAL()).GetWithTableNameListByNodeId(nodeId);
            if (TitleList == null)
                return null;
            foreach (ModelFieldInfoWithTableName info in TitleList)
            {

                if (info.FieldListDisplay || info.FieldTypeStr != "text")
                {
                    if (info.IsTitleField)
                    {
                        strExtColumns += "," + info.TableName + "." + info.FieldName + "," + info.TableName + "." + info.FieldName + " AS '$_title'";
                    }
                    else
                    {
                        strExtColumns += "," + info.TableName + "." + info.FieldName;
                    }

                    if (strExtTable == "")
                    {
                        strExtTable = info.TableName;
                    }
                }
            }
            if (strExtTable == "") { return null; }
            #endregion

            strShowColumns = strBaseColumns + strExtColumns;
            strTableName = strBaseTable + " left join " + strExtTable + " on " + strBaseTable + ".ExtendId=" + strExtTable + "." + strExtTable + "id";

            return new CommonManage().GetListByPager(strTableName, strShowColumns, pageNumber, pageSize, condition, orderby, out recordCount);
        }
        #endregion
    }
}
